<template>
	<div>
		<van-form :model="form" style="margin-top: 150px;">
      <van-icon name="success" color="#008000" size="48" />
			<h1 style="text-align: center;">鱼塘到家</h1>
			<van-field v-model="form.username" label="用户名" placeholder="请输入用户名"
				:rules="[{ required: true, message: '请填写用户名' }]" />
			<van-field v-model="form.password" type="password" label="密码" placeholder="请输入密码"
				:rules="[{ required: true, message: '请填写密码' }]" />
			<div>
				<span style="font-size: 12px; margin-left: 5%; color:crimson" @click="toForget">忘记密码</span>
				<span style="font-size: 12px; margin-left: 60%;  color:green" @click="toRegister">注册新用户</span>
			</div>
			<div style="margin: 16px;">
				<van-button round block type="primary" @click="login()">登录</van-button>
			</div>
		</van-form>
	</div>
</template>

<script>
	import axios from "axios"
	export default {
		data() {
			return {
				form: {},
			}
		},
		created() {

		},
		methods: {
			toRegister() {
				location.href = "#/register";
			},
			toForget() {
				location.href = "#/forget";
			},
      login() {
        axios.post(`http://localhost:10086/user/login`,this.form).then(res => {
          if (res.data.code == 200) {
            sessionStorage.setItem("userDB", JSON.stringify(res.data.user));
              location.href = "#/homepage";
            // if (res.data.user.lid == 3) {
            //   location.href = "#/homepage";
            // } else if (res.data.user.lid == 2) {
            //   location.href = "#/home";
            // }
            this.$message.success("登录成功");
          } else {
            this.$message.error(res.data.msg)
          }
        })
      },
		},
	}
</script>

<style>

</style>
